import openpyxl
import os
import sys
import shutil
from itertools import groupby
import json
import zipfile
from win32com.client import Dispatch, constants, gencache, DispatchEx


OrderNumber = "GR20200905010" # 测试订单号
PIUSerialNumber = "66526" # 测试设备序列号
SystermSerialNumber = "4.3.5.91" # 软件序列号
Hospital = "嵊州市人民医院" # 测试医院
HospitalAddress = "XX路"

ServiceTimeBefore = "2020/09/07" #术前服务报告服务日期
ServiceTimeAfter = "2020/09/07" #术后服务报告服务日期
ATPTestTimeStart = "21:02"
ATPTestTimeStop = "22:12"
CleanTimeStart = "17:30"
CleanTimeStop = "17:40"

FSE_Name = "吴文杰" # 工程师姓名

Time_ATP_1 = "20200907" # 术前时间
Time_ATP_2 = "20200907" # 术后时间
ATP1Folder_Time = "200907"

DateService_0943 = "2020-09-04"
CubeVol_0943 = "987.3426ml"
CubeDiag_0943 = "1.2397mm"
DC_High = "1.4mV"
DC_Low = "0.2mV"
SIDMinHeight_0943 = "89cm"
SIDMinHeight_0 = 116
SIDMinHeight_30 = 117
SIDMinHeight_45 = 116
SIDAverHeight_0943 = "91cm"
SIDAverHeight_0 = 116
SIDAverHeight_30 = 117
SIDAverHeight_45 = 118
SIDMaxHeight_0943 = "93cm"
SIDMaxHeight_0 = 117
SIDMaxHeight_30 = 118
SIDMaxHeight_45 = 118



# -------------------- 以上数据需要根据实际订单修改 ------------------ #
ServicePicture_Name = PIUSerialNumber + "_" + Time_ATP_1 + "_" \
                  + "WUWENJIE" + ".jpg" # 现场服务报告文件格式
File_590_Name = "Site inspection frm590_43_China_" \
                + OrderNumber + "_" + FSE_Name + "_" + Hospital \
                + "_" + PIUSerialNumber + ".xlsm"# 590 文件名格式xlsm
File_0943_Name = "FRM0943" + "_" + Hospital + "_" + PIUSerialNumber \
                 + "_" + Time_ATP_1 + "_" + "术前" + ".xltm" # 0943 文件名格式
ServiceReport_NameBefore = "服务报告" + "_" + Hospital + "_" + Time_ATP_1 \
                           + "_" + "术前" + ".xlsx" # 术前服务报告 文件名格式
ServiceReport_NameAfter = "服务报告" + "_" + Hospital + "_" + Time_ATP_2 \
                          + "_" + "术后" + ".xlsx"# 术后服务报告 文件名格式

# 1. 在Source_path先创建FirstWork_path
# 2. 在FirstWork_path分别创建MailWork_path、ATP1_workpath、ATP2_workpath
# 3. 在MailWork_path中：
#   3.1 创建年月日ATP1：
#       3.1.1 拷贝8分成功检测文件
#       3.1.2 copy 0943
#       3.1.3 copy 术前服务报告
# 4. 创建现场照片，
# 5. copy590工单，然后更改
# 6. 创建UserSettings_PIUSerialNumber_Time_ATP_1文件夹，copy文件
# 7. copy术后服务报告，更改拷贝至MailWork_path
Source_path = "E:/Report_Basic/吴文杰实习期_国润报告记录" # 测试报告总目录
FirstWork_path = Source_path + "/" + OrderNumber + "_" + Hospital + "_" + "报告" # 报告顶层目录
MailWork_path = FirstWork_path + "/" + OrderNumber + "_" + Hospital \
                + "_" + PIUSerialNumber + "_" + FSE_Name # 邮件报告目录
WEBpath = MailWork_path + "/" + OrderNumber + "_" + Hospital \
                + "_" + PIUSerialNumber + "_" + FSE_Name + "_WEB报告"
Testpath = MailWork_path + "/" + OrderNumber + "_" + Hospital \
                + "_" + PIUSerialNumber + "_" + FSE_Name + "_检测报告"

ATP1_TestBefore = MailWork_path + "_" + "术前" # 术前资料文件夹
ATP2_TestAfter = MailWork_path + "_" + "术后" # 术后资料文件夹
ATP1Folder_path = MailWork_path + "/" + ATP1Folder_Time + "ATP1"
UserSettingsCopyFilePath = r"E:/Report_Basic/UserSettings"   # 原始UserSettings目录，用于整体文件夹拷贝
ATPReport_path = UserSettingsCopyFilePath + "/" + "ServiceReports" # ServiceReports目录，用于拷贝ATP Report
UserSettings_dstpath = MailWork_path + "/" + "UserSettings" \
                       + "_" + PIUSerialNumber + "_" + Time_ATP_1 # UserSettings报告目录
Report_BasicPath = "E:/Report_Basic" # 报告模板目录
print(os.getcwd())